import { IFeidaoAiBrowserComponent } from '@dfeidao/atom-web/interfaces';
import nodejs from '@dfeidao/atom-web/msg/nodejs';

import get from '@dfeidao/atom-web/local/get';

export default async function a002(fd: IFeidaoAiBrowserComponent) {
	// 保存修改基本信息弹出框
	const node = get(fd, 'J') as { _id: string; industry_domain_name: string; industry_domain_no: string; };
	const id = node._id;

	const kh = fd.data.node.querySelector<HTMLInputElement>('[data-name="kh"]');
	const cust_name = kh.value;

	const dz = fd.data.node.querySelector<HTMLInputElement>('[data-name="dz"]');
	const contact_address = dz.value;

	const hy = fd.data.node.querySelector<HTMLInputElement>('[data-name="hy"]');
	const industry_domain_name1 = hy.value;

	const bz = fd.data.node.querySelector<HTMLInputElement>('[data-name="bz"]');
	const memo = bz.value;


	const oldname = node.industry_domain_name;
	let oldbh = node.industry_domain_no;
	if (oldname !== industry_domain_name1) {
		const data = get(fd, 'industry_domain') as { industry_domain_no: string };
		oldbh = data.industry_domain_no;
	}

	const res = await nodejs<{ code: number; result: string; }>('customer-care/zj-000008/s001', {
		filter: {
			_id: id,
			cust_name,
			contact_address,
			memo,
			industry_domain_no: oldbh,
			industry_domain_name: industry_domain_name1

		}
	});
	if (res.code === 1) {
		alert('成功！');
		window.location.reload();
	} else {
		alert('失败!');
	}

}
